package com.admission.web.admin;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.Attention;
import com.admission.service.AttentionManager;
import com.admission.web.CrudActionSupport;
@Namespace("/admin")
public class AttentionAdminAction extends CrudActionSupport<Attention> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8468044712244068194L;
	
	private Page<Attention> page = new Page<Attention>(5);
	private AttentionManager attentionManager;
	private List<Attention> contents;
	private List<String> content;
	private List<String> ids;

	public Attention getModel() {
		return null;
	}

	@Override
	public String list() throws Exception {
		if(attentionManager.list().isEmpty()){
			Attention atte = null;
			for(int i = 0; i < 5; i++){
				atte = new Attention();
				atte.setContent("");
				attentionManager.save(atte);
			}
		}
		List<PropertyFilter> filters = PropertyFilter
				.buildFromHttpRequest(Struts2Utils.getRequest());
		page = attentionManager.pageAttention(page, filters);
		contents = page.getResult();
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return null;
	}

	@Override
	public String save() throws Exception {
		Attention att = null;
		for(int i = 0; i < ids.size(); i++){
			att = attentionManager.getById(ids.get(i));
			att.setContent(content.get(i));
		}
		return this.list();
	}

	@Override
	public String delete() throws Exception {
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		
	}

	public Page<Attention> getPage() {
		return page;
	}

	public void setPage(Page<Attention> page) {
		this.page = page;
	}

	@Autowired
	public void setAttentionManager(AttentionManager attentionManager) {
		this.attentionManager = attentionManager;
	}

	public List<Attention> getContents() {
		return contents;
	}

	public void setContents(List<Attention> contents) {
		this.contents = contents;
	}

	public void setContent(List<String> content) {
		this.content = content;
	}

	public void setIds(List<String> ids) {
		this.ids = ids;
	}
	
}
